package com.novellotus.iov.carvice.utils;

import android.util.Base64;

/**
 * Created by Rich on 2017/8/7.
 */

public class Base64Utils {

    /**
     * 加密
     * 如果是Android的话，android.utils.Base64自带该功能：
     * Base64.encodeToString(encrypted, Base64.URL_SAFE|Base64.NO_WRAP);
     * Base64.decode(data, Base64.URL_SAFE)
     */
    public static String EncodesBase64(String str) {
        return Base64.encodeToString(str.getBytes(), Base64.URL_SAFE);
    }
    public static String EncodesBase64(byte[] bytes) {
        return Base64.encodeToString(bytes, Base64.URL_SAFE).replace("=","");
    }

    /**
     * 解密
     */
    public static String getFromBase64(byte[] encrypted) {
        return Base64.encodeToString(encrypted, Base64.URL_SAFE | Base64.NO_WRAP);
    }
}
